﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;


namespace DbF
{

    /// <summary>
    /// 数据访问类型
    /// </summary>
    public enum SqlSourceType
    {
        Oracle,
        SqlServer,
        MySql,
        Access,
        SqLite,
        Db2,
        PostgreSql
    }

    /// <summary>
    /// 有关数据库连接的接口
    /// </summary>
    public interface IDbHelper
    {
        #region Dapper操作方法
        /// <summary>
        /// 根据主键获取单一对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        T Get<T>(object id);

        /// <summary>
        /// 根据条件获取单一对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        T GetByWhere<T>(string strWhere);
       

        /// <summary>
        /// 获取实体对象列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parm">参数</param>
        /// <returns></returns>
        IEnumerable<T> GetList<T>(object parm);

        /// <summary>
        /// 获取实体对象列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strwhere">Where条件</param>
        /// <returns></returns>
        IEnumerable<T> GetList<T>(string strwhere);

        /// <summary>
        /// 实体对象列表分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pageNumber">查询第几页</param>
        /// <param name="rowsPerPage">每页显示的条数</param>
        /// <param name="strWhere">Where条件</param>
        /// <param name="orderby">排序字段</param>
        /// <param name="count">数据总页数</param>
        /// <returns></returns>
        IEnumerable<T> GetListPage<T>(int pageNumber, int rowsPerPage, string strWhere, string orderby, ref int count);

        /// <summary>
        /// 批量插入数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="entities"></param>
        /// <returns></returns>
        int InsertMultiple<T>(string sql, IEnumerable<T> entities);

        /// <summary>
        /// 根据实体对象插入数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        int? Insert(object entity);

        /// <summary>
        /// 带事务的实体对象插入数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        int? InsertTran(object entity);

        /// <summary>
        /// 根据实体对象插入数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        Guid InsertGuid(object entity);

        /// <summary>
        /// 带事务的实体对象插入数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        Guid InsertTranGuid(object entity);

        /// <summary>
        /// 根据实体对象更新数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        int? Update(object entity);

        /// <summary>
        /// 带事务的实体对象更新数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        int? UpdateTran(object entity);

        /// <summary>
        /// 根据实体对象删除数据
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        int? Delete<T>(string id);

        /// <summary>
        /// 带事务的实体对象更新数据
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        int? DeleteTran<T>(string id);

        /// <summary>
        /// 根据实体对象删除数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        int? Delete(object entity);

        /// <summary>
        /// 带事务的实体对象更新数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        int? DeleteTran(object entity);

        /// <summary>
        /// 根据实体对象删除数据列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        int? DeleteList<T>(object param);

        /// <summary>
        /// 带事务的实体对象删除数据列表
        /// </summary>
        /// <param name="param">参数</param>
        /// <returns></returns>
        int? DeleteListTran<T>(object param);

        /// <summary>
        /// 根据实体对象删除数据列表
        /// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns></returns>
        int? DeleteList<T>(string strWhere);

        /// <summary>
        /// 带事务的实体对象删除数据列表
        /// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns></returns>
        int? DeleteListTran<T>(string strWhere);

        /// <summary>
        /// 带事务的实体对象删除数据列表
        /// </summary>
        /// <param name="strWhere">Where条件</param>
        /// <returns></returns>
        int RecordCount<T>(string strWhere);
        #endregion

        #region 根据 SQL 返回影响行数
        /// <summary>
        /// 根据SQL返回影响行数
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        object GetObjectValue(StringBuilder sql);
        /// <summary>
        /// 根据SQL返回影响行数,带参数
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="param">参数化</param>
        /// <returns></returns>
        object GetObjectValue(StringBuilder sql, object param);
        #endregion

        #region 根据 SQL 执行
        /// <summary>
        ///  根据SQL执行
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns>object</returns>
        int ExecuteBySql(StringBuilder sql);
        /// <summary>
        ///  根据SQL执行,带参数
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="param">参数化</param>
        /// <returns>object</returns>
        int ExecuteBySql(StringBuilder sql, object param);
        /// <summary>
        ///  根据SQL执行,带参数,不带事务
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="param">参数化</param>
        /// <returns>object</returns>
        int ExecuteBySqlNotTran(StringBuilder sql, object param);
        /// <summary>
        /// 批量执行SQL语句
        /// </summary>
        /// <param name="sqls">sql语句</param>
        /// <param name="param">参数化</param>
        /// <returns></returns>
        int BatchExecuteBySql(object[] sqls, object[] param);
        #endregion

        #region 根据 SQL 返回 DataTable 数据集
        /// <summary>
        /// 根据 SQL 返回 DataTable 数据集
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns>DataTable</returns>
        DataTable GetDataTableBySqL(StringBuilder sql);
        /// <summary>
        /// 根据 SQL 返回 DataTable 数据集，带参数
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="param">参数化</param>
        /// <returns>DataTable</returns>
        DataTable GetDataTableBySqL(StringBuilder sql, object param);
        #endregion

        #region 根据 SQL 返回 IList
        /// <summary>
        /// 根据 SQL 返回 IList
        /// </summary>
        /// <typeparam name="T">实体类</typeparam>
        /// <param name="sql">语句</param>
        /// <returns></returns>
        List<T> GetDataListBySqL<T>(StringBuilder sql);
        /// <summary>
        /// 根据 SQL 返回 IList,带参数 (比DataSet效率高)
        /// </summary>
        /// <typeparam name="T">实体类</typeparam>
        /// <param name="sql">Sql语句</param>
        /// <param name="param">参数化</param>
        /// <returns></returns>
        List<T> GetDataListBySqL<T>(StringBuilder sql, object param);
        #endregion

        #region 数据分页 返回 DataTable

        /// <summary>
        /// 数据分页
        /// </summary>
        /// <param name="sql">传入要执行sql语句</param>
        /// <param name="param">参数</param>
        /// <param name="orderby">排序字段和排序类型</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="count">返回查询条数</param>
        /// <returns>返回Table类型</returns>
         DataTable GetPageTable(string sql, object param, string orderby, int pageIndex, int pageSize,ref int count);

        /// <summary>
        /// 数据分页
        /// </summary>
        /// <param name="sql">传入要执行sql语句</param>
        /// <param name="orderby">排序字段和排序类型</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="count">返回查询条数</param>
        /// <returns>返回Table类型</returns>
        DataTable GetPageTable(string sql, string orderby, int pageIndex, int pageSize, ref int count);
       
        #endregion

        #region 数据分页 返回 ILis

        /// <summary>
        /// 数据分页
        /// </summary>
        /// <param name="sql">传入要执行sql语句</param>
        /// <param name="param">参数</param>
        /// <param name="orderby">排序字段和排序类型</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="count">返回查询条数</param>
        /// <returns>返回List类型</returns>
        IList GetPageList<T>(string sql, object param, string orderby, int pageIndex, int pageSize, ref int count);

        /// <summary>
        /// 数据分页
        /// </summary>
        /// <param name="sql">传入要执行sql语句</param>
        /// <param name="orderby">排序字段和排序类型</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="count">返回查询条数</param>
        /// <returns>返回List类型</returns>
        IList GetPageList<T>(string sql, string orderby, int pageIndex, int pageSize, ref int count);

        #endregion


    }
}
